package geppetto.phraseHMM.phraseExtraction.extractedphrase.data;

import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairData;

import java.util.ArrayList;
import java.util.HashMap;

public class SubPathsData extends ExtractedPhrasePairData{

	double subpaths;
	
	public SubPathsData(double subpaths) {
		super();
		this.subpaths = subpaths;
	}	

	public double getSubpaths() {
		return subpaths;
	}


	public void setSubpaths(double subpaths) {
		this.subpaths = subpaths;
	}


	@Override
	public void merge(ArrayList<HashMap<String, ExtractedPhrasePairData>> generalData, ArrayList<ExtractedPhrasePairData> data) {
		if(data.contains(this)){
			data.remove(this);
		}
		
		double n = 1;
		for(ExtractedPhrasePairData d : data){
			if(d instanceof SubPathsData){
				subpaths += ((SubPathsData)d).getSubpaths();
				n++;
			}
			else{
				System.err.println("trying to merge an instance of SubPhrasesData to with another type of class");
				System.exit(-1);
			}
		}
		subpaths = subpaths / n;
	}

	@Override
	public String toString() {
		return String.valueOf(subpaths);
	}
	
	public static SubPathsData parseString(String s) {
		return new SubPathsData(Double.parseDouble(s));
	}	
}
